package com.glsc.ngateway.amdoc.handler;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.Date;

/**
 * @Title: InterfaceReponse
 * @Description: 接口响应类
 * @author: 张宁
 * @version: 1.0.0
 * @date: 2020/12/21 16:29
 */


public class InterfaceReponse<T> {


    /**
     * 消息状态
     */
    public String status;

    /**
     * 消息Code
     */
    public Integer code;

    /**
     * 消息体
     */
    @JsonInclude(value = JsonInclude.Include.NON_NULL)  // 为NULL则不返回值
    public String msg;


    @JsonInclude(value = JsonInclude.Include.NON_NULL)
    public T data;


    @JSONField(format = "yyyy-MM-dd hh:mm:ss")
    private static Date timestamp = new Date();

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Date getTimestamp() {
        return timestamp;
    }

    public static void setTimestamp(Date timestamp) {
        InterfaceReponse.timestamp = timestamp;
    }

    /**
     * @param content
     * @return
     * @Description 成功消息返回码
     */
    public static InterfaceReponse returnSuccss(String content) {
        InterfaceReponse response = new InterfaceReponse();
        response.setStatus(MessageEum.SUCCESS.getStatus());
        response.setCode(MessageEum.SUCCESS.getCode());
        response.setMsg(content);
        return response;
    }

    public static InterfaceReponse returnSuccss(Object data) {
        InterfaceReponse response = new InterfaceReponse();
        response.setStatus(MessageEum.SUCCESS.getStatus());
        response.setCode(MessageEum.SUCCESS.getCode());
        response.setData(data);
        return response;
    }


    /**
     * @param content
     * @return
     * @Description 错误消息
     */
    public static InterfaceReponse returnError(String content) {
        InterfaceReponse response = new InterfaceReponse();
        response.setStatus(MessageEum.ERROR.getStatus());
        response.setCode(MessageEum.ERROR.getCode());
        response.setMsg(content);
        return response;
    }

    public static InterfaceReponse returnError(String content, Integer code, String status) {

        InterfaceReponse response = new InterfaceReponse();

        response.setStatus(status);
        response.setCode(code);
        response.setMsg(content);
        return response;

    }

    /**
     * @param content
     * @return
     * @Description 异常消息
     */
    public static InterfaceReponse returnException(String content) {
        InterfaceReponse response = new InterfaceReponse();
        response.setStatus(MessageEum.EXCEPTION.getStatus());
        response.setCode(MessageEum.EXCEPTION.getCode());
        response.setMsg(content);
        return response;
    }

    public static InterfaceReponse returnException(Object data) {
        InterfaceReponse response = new InterfaceReponse();
        response.setStatus(MessageEum.EXCEPTION.getStatus());
        response.setCode(MessageEum.EXCEPTION.getCode());
        response.setData(data);
        return response;
    }


}
